package com.rongzhe.house.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.rongzhe.house.R;
import com.rongzhe.house.entity.voo.HouseOverview;
import com.rongzhe.house.presenter.MyFavoritePresenter;
import com.rongzhe.house.presenter.PageContoller;
import com.rongzhe.house.ui.adapter.HouseAdapter;
import com.rongzhe.house.ui.view.smoothlist.SmoothListView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by huang on 2017/12/10.
 */

public class MyFavoriteFragment extends BaseFragment<MyFavoritePresenter>
        implements PageContoller.PageControlInteface<HouseOverview> {
    @BindView(R.id.text_no_house)
    TextView textNoHouse;
    @BindView(R.id.list_house)
    SmoothListView listHouse;
    Unbinder unbinder;
    private HouseAdapter mAdapter;

    @Override
    protected MyFavoritePresenter createPresenter() {
        return new MyFavoritePresenter(this);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_favorite, container, false);
        unbinder = ButterKnife.bind(this, rootView);
        mAdapter = new HouseAdapter(getContext());
        listHouse.setAdapter(mAdapter);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void addData(List<HouseOverview> houseInfos) {
        mAdapter.addHouseInfos(houseInfos);
    }

    @Override
    public void setData(List<HouseOverview> houseInfos) {
        mAdapter.setHouseInfos(houseInfos);
    }

    @Override
    public void loadData(boolean append) {
        mPresenter.loadStaredList(append);
    }

    @Override
    public SmoothListView getListView() {
        return listHouse;
    }

    @Override
    public void setAsNoData(boolean noData) {

    }

    public void setEmptyViewShowing(boolean show) {
        textNoHouse.setVisibility(show ? View.VISIBLE : View.GONE);
        listHouse.setVisibility(show ? View.GONE : View.VISIBLE);
    }
}
